package com.minivision.fdiot.common;

import lombok.Data;

import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import io.swagger.annotations.ApiModel;

/**
 * Rest接口响应
 * @author hughzhao
 * @2018年3月1日
 * @param <T>
 */
@Data
@ApiModel(description = "通用返回结构")
@JsonInclude(Include.NON_EMPTY)
public class RestResult<T> {
  
  private String requestId = UUID.randomUUID().toString();
  private int timeUsed;
  //为0表示成功，非0失败
  private int status;
  //错误描述
  private String message;
  private T data;

  public RestResult() {
    
  }

  public RestResult(T data) {
    this.data = data;
  }

  public RestResult(Throwable t) {
    this.message = t.getMessage();
    this.status = -1;
  }
  
  public RestResult(Throwable t, int status) {
    this.message = t.getMessage();
    this.status = status;
  }
  
  public RestResult(String message, int status) {
    this.message = message;
    this.status = status;
  }
  
}
